Array.prototype.remove = function(b) {
    var a = this.indexOf(b);
    if (a >= 0) {
        this.splice(a, 1);
        return true;
    }
    return false;
};
function counter(arrays,index,text,length) {
    if(length == undefined)length = 0;
    if(text.length > length){
        if(arrays.indexOf(index) == -1){
            arrays.push(index);
        }
    }else{
        arrays.remove(index);
    }
}

var createUUID = (function (uuidRegEx, uuidReplacer) {
    return function () {
        return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
    };
})(/[xy]/g, function (c) {
    var r = Math.random() * 16 | 0,
        v = c == "x" ? r : (r & 3 | 8);
    return v.toString(16);
});

$.fn.extend({
    Upload: function (options) {
        var defaults = {
            callback: function (result) {

            },
            url : '/file/upload.html'
        };
        options = $.extend(defaults, options);
        var uploader = $(this);

        var createFileFunc = function (width, height) {
            var file = $('<input type="file" name="files" class="q_upload" />');
            file.css({
                position: 'absolute',
                left: '0',
                width: width + 'px',
                top: '0',
                height: height + 'px',
                filter: 'alpha(opacity=0)',
                opacity: '0',
                cursor: 'pointer'
            });
            file.change(function () {
                var uploadFile = $(this);
                var height = uploadFile.height();
                var width = uploadFile.width();
                var uploadFileParent = $(this).parent();
                var fileName = createUUID();
                var url = options.url;

                var form = $('<form method="post" action="'+url+'" enctype="multipart/form-data">' +
                    '</form>');
//                        var upFile = $('<input type="file" name="file" value="'+uploadFile.val()+'">');
                form.append(uploadFile);
                uploadFileParent.append(createFileFunc(width, height));
                form.ajaxSubmit(function (result) {
                    var img = JSON.parse(JSON.stringify(result));
                    //options.callback(img);
                    uploadFileParent.trigger('callback',img);
                });
            });
            return file;
        };
        $(this).each(function (i, element) {
            var btn = $(element);
            var height = btn.height();
            var width = btn.width();
            btn.wrap('<div style="position: relative;"></div>');
            var upBtn = btn.parent();
            var file = createFileFunc(width, height);

            upBtn.append(file);
            upBtn.unbind('callback').bind('callback', options.callback);
        });
    }
});

/*弹出框 */
function popUp(opts){
    var defaultOpts = {
        title:'',
        content:'',
        button1:'',
        button2:'',
        cancel:function(){},
        determine:function(){}
    };
    defaultOpts = $.extend(defaultOpts,opts)
    var toast = $('<div class="showOrHide" style="text-align: center;height: 100%;overflow: visible;position: fixed;width:100%;top: 0;z-index: 50;background-color: rgba(50, 50, 50, 0.35);" >'
        +'<div style="position: relative;background-color: #ffffff;width: 300px;margin: 170px auto;border-radius: 8px;">'
        +'<div class="title" style="padding-top: 10px;font-weight: bold;color: #D6B52A; ">'+defaultOpts.title+'</div>'
        +'<div class="contents" style="padding: 15px;">'+defaultOpts.content +'</div>'
        +'<div style="clear: both;height: 40px;"></div>'
        +'<div class="btn" style="color: #9E9E9E;position: absolute;bottom: 0px;width: 100%;left: 0;text-align: center;">'
        +'<span class="cancel" style="height: 35px;line-height: 35px;width: 49%;display: inline-block;background-color: #D6B52A; color: #FFFFFF;border-radius: 5px;">'+defaultOpts.button1+'</span>'
        +'</div>'
        +'</div>'
        +'</div>');
    $('body').append(toast);
    if(defaultOpts.title!="" && defaultOpts.title!=undefined){
        toast.find('.cancel').bind('click',defaultOpts.cancel);
        toast.find('.determine').bind('click',defaultOpts.determine);
    }else{
        toast.find('.cancel').bind('click',defaultOpts.cancel);
        toast.find('.determine').bind('click',defaultOpts.determine);
    }
}

/*弱提示 3秒*/
function toast(img,content){
    var toast = $('<div id="toast" style="position:fixed; left: 0;top: 100px; bottom: 0; right: 0;margin: auto;width:150px;height:90px;padding:10px 0;text-align:center;background:rgba(0,0,0,0.6);border-radius:14px;color:white;"><img width="40px" src="imgs/'+img+' " /><div style="padding: 8px 0;">'+content+'</div></div>');
    $('body').append(toast);
}

/*弱提示 3秒 不带图片的*/
function popUpContent(content){
    /*var height = $('body').height()-100;
    $(toast).css("margin-top",height);*/
    var toast = $('<div style="position:fixed; left: 0; bottom: 230px; right: 0;margin:0 auto;width:140px; padding:10px 0;text-align:center;background:rgba(0,0,0,0.6);border-radius:14px;color:white;"><div style="padding: 8px 0;">'+content+'</div></div>');

    $('body').append(toast);
    setTimeout(function(){
        toast.remove();
    },2000);
}

/*时间格式  yy/MM/dd */
var yyMMdd = function(strTime) {
    var time =  strTime.split("-")[0].substring('2','4')+"/"+strTime.split("-")[1]+"/"+strTime.split("-")[2];
    return time;
}